package com.yxs.school.api.controller;


import com.yxs.school.api.entity.Credits;
import com.yxs.school.api.service.ICreditsService;
import com.yxs.school.result.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 积分 前端控制器
 * </p>
 *
 * @author whp
 * @since 2019-11-15
 */
@RestController
@RequestMapping("/api/credits")
public class CreditsController {
    @Resource
    private ICreditsService iCreditssService;
    @PostMapping("save")
    public R save(@RequestBody Credits credits) {
        boolean flag = iCreditssService.save(credits);
        if (flag) {
         return    R.data(200,null,"成功");
        }else {
          return   R.fail(400,"失败");
        }
    }
    @DeleteMapping("delete")
    @PostMapping("update")
    public R delete(@RequestBody List<Integer> ids) {
        boolean flag = iCreditssService.removeByIds(ids);
        if (flag) {
            return R.data(200,null,"成功删除"+ids.size()+"条");
        }else {
            return R.fail(400,"失败");
        }
    }
    public R update(@RequestBody Credits credits) {
        boolean flag = iCreditssService.updateById(credits);
        if (flag) {
           return R.data(200,null,"成功");
        }else {
            return R.fail(400,"失败");
        }
    }
    @GetMapping("list")
    public R list() {
        List<Credits> list =iCreditssService.list();
        return R.data(200,list,"成功");
    }
    @GetMapping("detail")
    public R detail(Integer id) {
        Credits credits = null;
        credits = iCreditssService.getById(id);
        if (credits == null)
        return R.data(200,credits,"成功");
        else return R.fail(400,"查询失败");
    }
}
